import bacnet_io
import re

bn = bacnet_io.BacnetIO('db_brower')

type_filter = [
  bacnet_io.OBJECT_ANALOG_INPUT,
  bacnet_io.OBJECT_ANALOG_OUTPUT,
  bacnet_io.OBJECT_ANALOG_VALUE,
  bacnet_io.OBJECT_BINARY_INPUT,
  bacnet_io.OBJECT_BINARY_OUTPUT,
  bacnet_io.OBJECT_BINARY_VALUE
]

unit_map = {
  3: 'Amps',
  27: 'Hertz',
  47: 'Watts',
  48: 'Kilowatts',
  64: 'Deg F',
  71: 'Hours',
  83: 'Gallons',
  89: 'GPM',
  95: 'None',
  98: 'Percent',
}

def path(o):
  n = o.name.split('/')[1]
  n = re.sub('\.|:|_','/', n)
  n = n.replace(' ', '_')
  return '/' + n

def obj_id(o):
  return o.parent.name + '/' + o.name

for o in bn.list(sort = True):
  if o.name.startswith('NAE00806603BECA/') and o.get_type() in type_filter:
    (unit_id, unit_str) = o.units or (-1, '')
    units = unit_map[unit_id] if unit_id in unit_map else unit_str

    print '%s,%s,%s,%s' % (obj_id(o), path(o), o.desc, units)
